package com.lefeng.cockpit.datax.dao.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.lefeng.cockpit.common.bean.po.job.JobLogPO;
import com.lefeng.cockpit.datax.dao.JobLogDao;
import com.lefeng.cockpit.datax.dao.mapper.JobLogMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class JobLogDaoImpl implements JobLogDao {

    @Resource
    private JobLogMapper jobLogMapper;

    @Override
    public void save(JobLogPO jobLogPO) {
        jobLogMapper.insert(jobLogPO);
    }

    @Override
    public void updateTriggerInfo(JobLogPO jobLogPO) {
        jobLogMapper.updateById(jobLogPO);
    }

    @Override
    public int updateProcessId(Integer logId, String processId) {
        JobLogPO jobLogPO = new JobLogPO();
        jobLogPO.setId(logId);
        jobLogPO.setProcessId(processId);
        LambdaUpdateWrapper<JobLogPO> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(JobLogPO::getId, jobLogPO.getId()); // WHERE 条件
        updateWrapper.set(JobLogPO::getProcessId, jobLogPO.getProcessId()); // 更新值
        return jobLogMapper.update(jobLogPO, updateWrapper);
    }

    @Override
    public JobLogPO load(Integer logId) {
        return jobLogMapper.selectById(logId);
    }

    @Override
    public void updateHandleInfo(JobLogPO jobLogPO) {
        LambdaUpdateWrapper<JobLogPO> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(JobLogPO::getId, jobLogPO.getId()); // WHERE 条件

        updateWrapper.set(JobLogPO::getHandleTime, jobLogPO.getHandleTime()); // 更新值
        updateWrapper.set(JobLogPO::getHandleCode, jobLogPO.getHandleCode()); // 更新值
        updateWrapper.set(JobLogPO::getHandleMsg, jobLogPO.getHandleMsg()); // 更新值

        jobLogMapper.update(jobLogPO, updateWrapper);


    }

    @Override
    public Map<String, Object> findLogReport(Date from, Date to) {
        return jobLogMapper.findLogReport(from, to);
    }

    @Override
    public List<Long> findClearLogIds(int i, int i1, Date clearBeforeTime, int i2, int i3) {
        return null;
    }

    @Override
    public void clearLog(List<Long> logIds) {

    }
}
